<template>
	<view>
		<clientele-item v-for="(item,index) in leadList" :key="index" :item="item" @click="leadClick(item)">
		</clientele-item>
		<u-loadmore :status="status" />
		<fab @fabClick="fabClick"></fab>
		<!-- <uni-fab horizontal="right" @fabClick="fabClick"></uni-fab> -->

		<u-popup ref="popup" v-model="show" mode="center" border-radius="14" :mask-close-able="false" :closeable="true">
			<lead-add-view @addLeadEvent="addLeadSuccess"></lead-add-view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getMyLeads,
	} from '@/api/clientele.js'
	import LeadAddView from '@/pages_operate/clientele/components/lead-add-view.vue'
	import Fab from '@/components/fab.vue'
	import ClienteleItem from '@/pages_operate/clientele/components/clientele-item.vue'
	export default {
		components: {
			LeadAddView,
			Fab,
			ClienteleItem
		},
		data() {
			return {
				status: 'loadmore',
				page: -1,
				leadList: [],
				show: false,
			}
		},
		onLoad() {
			this.getLeads(this.page);
		},
		methods: {
			getLeads(page) {
				if (page === -1) {
					
				}
				const areaId = this.$store.state.user.tchInfo.area.id;
				getMyLeads(areaId, '', page + 1, 20).then(res => {
					console.log(res);
					if (res.data.last) {
						this.status = 'nomore';
					}
					this.page = res.data.number;
					if (this.page === 0) {
						this.leadList = res.data.content;
					} else {
						this.leadList = this.leadList.concat(res.data.content);
					}
				})
			},
			
			loadMore() {
				if (this.status === 'nomore') {
					return;
				}
				this.status = 'loading';
				this.getLeads(this.page);
			},
			
			onReachBottom() {
				this.loadMore();
			},

			leadClick(item) {
				uni.navigateTo({
					url: `pages_operate/clientele/lead-detail-page?leadsId=${item.id}&type=1`,
					events: {
						addSuccess: (data) => {
							this.page = -1
							this.getLeads(this.page);
						}
					},
					success: function(res) {
					}
				})
			},

			fabClick() {
				const that = this;
				uni.navigateTo({
					url: 'pages_operate/clientele/lead-add-page',
					events: {
						addSuccessEvent: function(data) {
							console.log('addSuccessEvent')
							that.addLeadSuccess()
						},
					}
				})
			},

			addLeadSuccess() {
				this.show = false;
				this.page = -1;
				this.getLeads(this.page);
			},

			getStateString(item) {
				let state = '';
				switch (item.status) {
					case 1:
						state = '未处理';
						break;
					case 2:
						state = '初访';
						break;
					case 3:
						state = '已邀约';
						break;
					case 4:
						state = '已到访';
						break;
					case 5:
						state = '不感兴趣';
						break;
					case 6:
						state = '未接通';
						break;
					case 7:
						state = '地域不符';
						break;
					case 8:
						state = '孩子超龄';
						break;
					case 9:
						state = '无效的联系方式';
						break;
					default:
						state = '未知';
				}
				return state;
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 80%!important;
		
	}
	

</style>
